<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Layout extends CI_Model {

    private $head = 'template/head';
    private $header = 'template/header';
    private $body = 'template/body';
    private $footer = 'template/footer';
    private $content = '';
    private $js = array('jquery-ui-1.10.1.custom/js/jquery-1.9.1',
        'jquery-ui-1.10.1.custom/js/jquery-ui-1.10.1.custom'
    );
    private $css = array(
        'table',
        'jquery-ui/jquery-ui-1.10.1.custom.min'
    );
    private $title = '';

    public function __construct() {
        parent::__construct();
    }

    public function title($title) {
        $this->title = $title;

        return $this;
    }

    public function view($viewUrl, $data = null) {
        $this->content = $this->load->view($viewUrl, $data, true);

        $this->load->view($this->head, array('js' => $this->js, 'css' => $this->css, 'title' => $this->title));
        $this->load->view($this->header, array('title' => $this->title));
        $this->load->view($this->body, array('output' => $this->content));
        $this->load->view($this->footer);
    }

    public function js($fileUrl) {
        if (is_array($fileUrl)) {
            foreach ($fileUrl as $file) {
                $this->js[] = $file;
            }
        } else {
            $this->js[] = $fileUrl;
        }
        return $this;
    }

    public function css($fileUrl) {
        if (is_array($fileUrl)) {
            foreach ($fileUrl as $file) {
                $this->css[] = $file;
            }
        } else {
            $this->css[] = $fileUrl;
        }
        return $this;
    }
    
    public function user_can($right) {
        $this->load->model('account_model');
        if(!$this->account_model->can($right)) {
            redirect('accessDenied');
        }
        
        return $this;
    }

}

?>